package com.winchain.chainbill.asset.biz.credit.service.impl;

import com.shell.bee.acct.transaction.po.AcctTxRec;
import com.shell.framework.command.CallbackContext;
import com.shell.framework.command.ChainCallback;
import com.winchain.chainbill.chain.callback.CallbackService;
import com.winchain.chainbill.trade.cmd.TranCallbackCmd;
import com.winchain.chainbill.trade.cmd.TranRollbackCmd;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("assetsMgtCallbackService")
public class AssetsMgtCallbackServiceImpl implements CallbackService {
	@Autowired
	private TranCallbackCmd<AcctTxRec> tranCallbackCmd;
	@Autowired
	private TranRollbackCmd<AcctTxRec> tranRollbackCmd;

	public String getType() {
		return "dist_rsrv";
	}

	public void confirm(AcctTxRec tran) {
		CallbackContext<AcctTxRec, AcctTxRec> context = new CallbackContext();
		context.setSource(tran);
		context.setTarget(tran);

		ChainCallback<AcctTxRec, AcctTxRec> ccb = new ChainCallback();

		ccb.add(this.tranCallbackCmd);
		ccb.callback(context);
	}

	public void cancel(AcctTxRec tran) {
		CallbackContext<AcctTxRec, AcctTxRec> context = new CallbackContext();
		context.setTarget(tran);

		ChainCallback<AcctTxRec, AcctTxRec> ccb = new ChainCallback();
		ccb.add(this.tranRollbackCmd);
		ccb.callback(context);
	}
}
